package com.itheima.tlias.mapper;

import com.itheima.tlias.pojo.Dept;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DeptMapper {
	//方式一使用@Results注解解决 驼峰转 转 下划线映射问题
	//@Results(id = "deptResult", value = {
	//		@Result(column = "create_time", property = "createTime"),
	//		@Result(column = "update_time", property = "updateTime")
	//})

	//方式二使用别名
	//@Select("select id, name, create_time as createTime, update_time as updateTtime from dept order by update_time")

	//方式三使用mybatis.configuration.map-underscore-to-camel-case: true
	@Select("select * from dept order by update_time")
	List<Dept> list();

	@Select("select * from dept where id = #{id}")
	Dept getById(Integer id);

	@Delete("delete from dept where  id = #{id}")
	int delete(Integer id);

	@Insert("insert into dept(name, create_time, update_time) " +
			"values(#{name}, #{createTime}, #{updateTime})")
	void save(Dept dept);

	@Insert("update dept set name = #{name}, update_time = #{updateTime} where id = #{id}")
	void updateById(Dept dept);
}
